package com.li.spark.optimization

import org.apache.spark.{SparkConf, SparkContext}

object RepartitionOp {
  def main(args: Array[String]): Unit = {
    val sc: SparkContext = getSparkContext

    val dataRDD = sc.parallelize(Array(1, 2, 3, 4, 5))
    //重新设置RDD的分区数量，会产生shuffle
    dataRDD.repartition(3).foreachPartition(it => {
      println("_____")
    })

    sc.stop();
  }


  private def getSparkContext = {
    //创建SparkContext
    val conf = new SparkConf();
    conf.setAppName("RepartitionOp").setMaster("local");
    new SparkContext(conf);
  }
}
